package net.flyinggroup.reactor.handson;

import net.flyinggroup.util.lang.ThreadUtil;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

public class WebClientMain {
    public void readFibonacciNumbers() {
        WebClient client = WebClient.create("http://localhost:8080");

        Flux<Long> result = client.get()
                .uri("fibo").accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToFlux(Long.class)
                .take(10L, true);

        result.subscribe(System.out::println, Throwable::printStackTrace);
    }

    public static void main(String[] args) {
        WebClientMain self = new WebClientMain();
        self.readFibonacciNumbers();
        ThreadUtil.sleep(30 * 1000);
    }
}
